<form action="" method="post">
	<fieldset style="display: inline-block;">
		<legend><h2>Call Hello Web Service</h2></legend>
		<table>
			<tr>
				<th valign="top">Config (Service WSDL)</th>
				<td>
					<input type="text" name="wsdl" size="100" value="<?php echo (isset($_POST['wsdl']) ? $_POST['wsdl'] : '')?>" /> 
					<br />* e.g. http://localhost/duongtohuong-demo/PHP/SOAP-WebService/Server/hello.php?wsdl
				</td>
			</tr>
			<tr><th>Enter your name</th><td><input type="text" name="name" size="50" value="<?php echo (isset($_POST['name']) ? $_POST['name'] : '')?>" /></td></tr>
			<tr>
				<td colspan="2"><input type="submit" name="call" value="Call Hello" /> 
				<input type="checkbox" name="debug" <?php echo (isset($_POST['debug']) ? 'checked' : '')?> /> <label>Enable debug</label></td>
			</tr>
		</table>
	</fieldset>
</form>
<?php
if (isset($_POST['call'])) {
	// Pull in the NuSOAP code
	require_once('libs/nusoap.php');
	// Create the client instance
	$client = new nusoap_client($_POST['wsdl'], true);
	$client->soap_defencoding = 'UTF-8';
	$client->decode_utf8 = false;
	
	// Check for an error
	$err = $client->getError();
	if ($err) {
	    // Display the error
	    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
	    // At this point, you know the call that follows will fail
	}
	
	// Call the SOAP method
	$result = $client->call('hello', array('name' => $_POST['name']), 'urn:hello',    // namespace
	    'urn:hello#hello',                // soapaction
	    'rpc',                                // style
	    'encoded',                            // use
	    'Says hello to the caller' );
	// Check for a fault
	if ($client->fault) {
	    echo '<h2>Fault</h2><pre>';
	    print_r($result);
	    echo '</pre>';
	} else {
	    // Check for errors
	    $err = $client->getError();
	    if ($err) {
	        // Display the error
	        echo '<h2>Error</h2><pre>' . $err . '</pre>';
	    } else {
	        // Display the result
	        echo '<h2>Result</h2><pre>';
	        print_r($result);
	    echo '</pre>';
	    }
	}
	if (isset($_POST['debug'])) {
		// Display the request and response
		echo '<h2>Request</h2>';
		echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
		echo '<h2>Response</h2>';
		echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
		// Display the debug messages
		echo '<h2>Debug</h2>';
		echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
		//echo "endpoint: ".$client->endpoint;
	}
}
?>